<?php
//网络教研平台数据抓取
class sign extends control
{
	public function __construct()
	{
		header("Content-Type: text/html; charset=utf-8");
		set_time_limit(0); //设置不超时.
		parent::__construct();
		$this->p =  $this->app->loadClass('proving');//加载相关类
		$this->jyurl = 'http://vip.topfeel.com/plugin.php?id=k_misign:sign&amp;operation=qiandao&amp;formhash=c251b378&amp;format=empty';

		$this->p->cfile = '111.txt';
	}

	//http://localhost/get_data/pds/sign-aa
	public function aa()
	{
 
		//$url ="https://blog.csdn.net/z13615480737";
		$url ="https://blog.csdn.net/z13615480737/article/list/";
  
		for($i=1;$i<6;$i++){
           $url_list =$url.$i;
           $res = $this->geturl($url_list);
	          //截取
			 $res = strstr($res,'<div class="article-list">');
			 list($res,) = explode('<div class="bottom-pub-footer footer-box pub_fo">',$res);
			 preg_match_all('/\<h4.*>.*<a href="(.*)" target="_blank">/isU',$res,$h);
 			// a($h[1]);
			$data_res=$h[1];
 			foreach($data_res as $v){
	               $res1 = $this->geturl($v); 
	              
	               	echo($v.'..................<br />');
			ob_flush();
			flush();
		}
	              // a($res1);
			 }
		
		}
		 	   
		 	   // preg_match_all('/<h4.*>(.*)<\/h4>/isU',$res,$h);//toke
		 	// preg_match_all('/\<h4.*>.*<a href="(.*)" target="_blank">/isU',$res,$h);
		 	// preg_match_all('/<a href="(.*)/',$res,$h);
		 	//$data_res=$h[1];
		 	 // a($h[1]);
			// foreach($data_res as $v){

			  //             $res1 = $this->geturl($v); 
			  //             a($res1);
				// }

	}
	















	public function get1(){
		$md5_token = $this->indexpage();
		$this->login1();

		$url = 'http://www.yzmedu.com/Index/usersign';
		$post = array();
		$post['md5_token'] = $md5_token;

		$res = $this->p->curl($url,'POST',$post);

		a($res);
	}

	function login1(){

		$api = "http://www.yzmedu.com";
        $url0 = $api .'/Login/login_tel_check';
        $url1 = $api .'/Login/login_form_check';
        

		$post_data = array();

		$post_data ['tel'] = "13934207626";
		$post_data ['password'] = "yzm13934207626";

		$res = $this->p->curl($url1,'POST',$post_data,false,2);

		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$api);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		//curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		//preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);//获取session

		$a = curl_exec($ch);
		file_put_contents("11.txt", $a);
	}

	public function indexpage(){
		$url = 'http://www.yzmedu.com/';
		$res = $this->p->curl($url,'get',array(),1);

		preg_match_all('/md5_token="(.*?)";/m',$res,$toke);//toke
	
         $md5_token = $toke[1][0];
		//($md5_token);exit;
         return $md5_token;
	}

	public function geturl($url){
	        $headerArray =array("Content-type:application/json;","Accept:application/json");
	        $ch = curl_init();
	        curl_setopt($ch, CURLOPT_URL, $url);
	        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
	        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	        curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
	        $output = curl_exec($ch);
	        curl_close($ch);
	      
	        return $output;
	}

	//登录
	public function test_login(){
		/*$url = "http://192.168.11.83/xcyc2/jxjy/user-user_login";
		$post_data = array();
		$post_data ['user_name'] = "admin";
		$post_data ['user_pass'] = "123456";*/

		/*
		$url = "http://192.168.11.82:8088/login";

		$post_data ['name'] = "ldxadm";
		$post_data ['password'] = "123456";
		$post_data ['fingerId'] = "f34c24fe7ea294d5633a7630b49d7a6c";

		*/
        $api = "http://www.yzmedu.com";
        $url0 = $api .'/Login/login_tel_check';
        $url1 = $api .'/Login/login_form_check';
        

		$post_data = array();

		$post_data ['tel'] = "13934207626";
		$post_data ['password'] = "yzm13934207626";
		
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		//curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		//preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);//获取session

		$res = curl_exec($ch);
		a($res);exit;
       //a(curl_exec($ch));
		// HTTP/1.1 200 OK
		// Server: nginx
		// Date: Wed, 19 Aug 2020 02:47:09 GMT
		// Content-Type: text/html; charset=UTF-8
		// Transfer-Encoding: chunked
		// Connection: keep-alive
		// Set-Cookie: PHPSESSID=ca2h654mfcif1s1gormmq2btca; expires=Mon, 24-Aug-2020 02:47:09 GMT; Max-Age=432000; path=/
		// Expires: Thu, 19 Nov 1981 08:52:00 GMT
		// Cache-Control: no-store, no-cache, must-revalidate
		// Pragma: no-cache
 
 		a($m);exit;
	      $Hm_lvt="Hm_lvt_a16b4434939df95d0e9f553d7e3af9de=1596694269";
	      $Hm_lpvt="Hm_lpvt_a16b4434939df95d0e9f553d7e3af9de=".time();
	      $cookie = $m[1][0].";".$Hm_lvt.";".$Hm_lpvt.";";


	      $md5_token = $toke[1][0];

		//执行并获取HTML文档内容
	      $output = curl_exec($ch);
		//释放curl句柄
	      curl_close($ch);
		//$res = $this->p->curl($url2,'POST',$post_data,false,1);
	      a($output);exit;


	}


public function html_gettoke()
	{
		$url ="http://www.yzmedu.com/";
		$post_data = array();

		
		
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		
		preg_match_all('/md5_token="(.*?)";/m',curl_exec($ch),$toke);//toke
	
         $md5_token = $toke[1][0];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		a($md5_token);
		a($output);
         $this->test_login();
	}

	public function jiye()
	{
		$url = "http://vip.topfeel.com/k_misign-sign.html";
		//155
		$url1 = "http://vip.topfeel.com/plugin.php?id=k_misign:sign&operation=qiandao&formhash=c251b378&format=empty&inajax=1&ajaxtarget=JD_sign";
		$cookie_file1 = "wb9U_7c64_saltkey=cw60bZ9b;wb9U_7c64_lastvisit=1595399855;wb9U_7c64_auth=7bb8HVIDrSThkGTx8U0Meg3tjFWi86pz7V9f%2Ft4clGiqhmi48USktd%2Bzw6arY%2BjrtVcQJAGtqmLoRxIM3kahjYg;wb9U_7c64_nofavfid=1;wb9U_7c64_home_diymode=1;wb9U_7c64_asc0=2;UM_distinctid=173c7f75463511-0fc763bf3c3481-541d3410-232800-173c7f75464831;wb9U_7c64_sid=IqMe03;wb9U_7c64_ulastactivity=1acf%2Fw%2F0bYkFkvhZX%2FK9hp7kaKwlzoaKVBnNKmmMQl2DLi2EOBJ6;wb9U_7c64_noticeTitle=1;wb9U_7c64_sendmail=1;wb9U_7c64_lastact=1597108267%09plugin.php%09;";
		//189的
		$url2 = "http://vip.topfeel.com/plugin.php?id=k_misign:sign&operation=qiandao&formhash=7301919c&format=empty&inajax=1&ajaxtarget=JD_sign";
		$cookie_file2 = "wb9U_7c64_saltkey=Ze9SZ8SM;wb9U_7c64_auth=52bb%2BZppi1dAnHDOZSbRNs6g1e5PwrWBKPcAl0kfu6YiuiYj%2BXW8ergCRZeAjBIlee3SxlBhrN8qHIx1SrWiEg;wb9U_7c64_nofavfid=1;wb9U_7c64_home_diymode=1;wb9U_7c64_asc0=2;UM_distinctid=173463a63707d6-0dcbbe59bde24-4e4c0f20-232800-173463a63714e8;wb9U_7c64_sid=j8obO8;wb9U_7c64_ulastactivity=1929dEjSieOqeN59XfoT7h1snnL5%2F6ZwtIprxO0XEPJgWuGb7D5K;wb9U_7c64_noticeTitle=1;wb9U_7c64_sendmail=1;";
		$this->jiye1($url, $cookie_file1);

		$this->jiye1($url, $cookie_file2);
		sleep(5);
		$this->jiye1($url2, $cookie_file2);
		sleep(5);
		$this->jiye1($url1, $cookie_file1);
	}

	//115de
	public function jiye1($url, $cookie_file)
	{
		$url = $url;
		$cookie_file = $cookie_file;
		// $url = "http://vip.topfeel.com/plugin.php?id=k_misign:sign&operation=qiandao&formhash=c251b378&format=empty&inajax=1&ajaxtarget=JD_sign";
		// $cookie_file="wb9U_7c64_saltkey=cw60bZ9b;wb9U_7c64_lastvisit=1595399855;wb9U_7c64_auth=7bb8HVIDrSThkGTx8U0Meg3tjFWi86pz7V9f%2Ft4clGiqhmi48USktd%2Bzw6arY%2BjrtVcQJAGtqmLoRxIM3kahjYg;wb9U_7c64_nofavfid=1;wb9U_7c64_home_diymode=1;wb9U_7c64_asc0=2;UM_distinctid=173c7f75463511-0fc763bf3c3481-541d3410-232800-173c7f75464831;wb9U_7c64_sid=IqMe03;wb9U_7c64_ulastactivity=1acf%2Fw%2F0bYkFkvhZX%2FK9hp7kaKwlzoaKVBnNKmmMQl2DLi2EOBJ6;wb9U_7c64_noticeTitle=1;wb9U_7c64_sendmail=1;wb9U_7c64_lastact=1597108267%09plugin.php%09;";
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_COOKIE, $cookie_file);

		//执行并获取HTML文档内容
		$output = curl_exec($ch);

		//释放curl句柄
		curl_close($ch);
		print_r($output);
	}
	//189de
	public function jiye2()
	{

		$url = "http://vip.topfeel.com/plugin.php?id=k_misign:sign&operation=qiandao&formhash=7301919c&format=empty&inajax=1&ajaxtarget=JD_sign";
		$cookie_file = "wb9U_7c64_saltkey=Ze9SZ8SM;wb9U_7c64_auth=52bb%2BZppi1dAnHDOZSbRNs6g1e5PwrWBKPcAl0kfu6YiuiYj%2BXW8ergCRZeAjBIlee3SxlBhrN8qHIx1SrWiEg;wb9U_7c64_nofavfid=1;wb9U_7c64_home_diymode=1;wb9U_7c64_asc0=2;UM_distinctid=173463a63707d6-0dcbbe59bde24-4e4c0f20-232800-173463a63714e8;wb9U_7c64_sid=j8obO8;wb9U_7c64_ulastactivity=1929dEjSieOqeN59XfoT7h1snnL5%2F6ZwtIprxO0XEPJgWuGb7D5K;wb9U_7c64_noticeTitle=1;wb9U_7c64_sendmail=1;";
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_COOKIE, $cookie_file); 	//存储cookies

		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		print_r($output);
	}



	function quickSort($arr)
	{
		//先判断是否需要继续进行
		$length = count($arr);
		if ($length <= 1) {
			return $arr;
		}
		//选择第一个元素作为基准
		$base_num = $arr[0];
		//遍历除了标尺外的所有元素，按照大小关系放入两个数组内
		//初始化两个数组
		$left_array = array(); //小于基准的
		$right_array = array(); //大于基准的
		for ($i = 1; $i < $length; $i++) {
			if ($base_num > $arr[$i]) {
				//放入左边数组
				$left_array[] = $arr[$i];
			} else {
				//放入右边
				$right_array[] = $arr[$i];
			}
		}
		//再分别对左边和右边的数组进行相同的排序处理方式递归调用这个函数
		$left_array = quick_sort($left_array);
		$right_array = quick_sort($right_array);
		//合并
		return array_merge($left_array, array($base_num), $right_array);
	}


	//http请求
	public function http_request_get($lurl)
	{
		$cookie_file = dirname(__FILE__) . '/cookie.txt';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $lurl);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
		$res = curl_exec($ch);
		curl_close($ch);
		return $res;
	}

	//http请求POST
	public function http_request_post($lurl, $post_data)
	{
		$cookie_file = dirname(__FILE__) . '/cookie.txt';

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
		$res = curl_exec($ch);
		curl_close($ch);

		return $res;
	}

	//http请求POST
	public function http_request_post_no_cookie($lurl, $post_data)
	{

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		$res = curl_exec($ch);
		curl_close($ch);

		return $res;
	

	}






}
